class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(),intervals.end());
        vector<vector<int>> ans;
        for(auto& e:intervals)
        {
            if(!ans.empty()&&e[0]<=ans.back()[1])
            {
                ans.back()[1]=max(ans.back()[1],e[1]); //合并区间，更新右端点最大值
            }
            else
            {
                ans.emplace_back(e);
            }

        }

        return ans;
    }
};